# -*- coding: utf-8 -*-

'''eof
name:注册资本
code:EG03_RegisteredCapital
tableName:
columnName:
groups:企业通用模块
dependencies:EG_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import json
from datetime import datetime


def FormatData(tableName):
    try:
        eg = EG_DSJ.get("data").get("R1103V3")[0].get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]


def is_num(num):
    try:
        float(num)
        return True
    except:
        return False


def getEG03():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    try:
        basic_list = FormatData("basicList")
        if basic_list == [{}]:
            return u'缺失值'
        else:
            if len(basic_list) >= 1:
                for i in basic_list:
                    reg_cap = i.get("regCap")
                    if reg_cap not in null_type_list and is_num(reg_cap):
                        return round(float(reg_cap)*10000, 4)
                    else:
                        return u'缺失值'
                return u'缺失值'
            else:
                return u'缺失值'
    except:
        return u'缺失值'


if __name__ == "__main__":
    file_obj = open(r'../data/EG/EG03_RegisteredCapital/EG_DSJ.json', 'r')
    content = file_obj.read()
    EG_DSJ = json.loads(content, strict=False)
    aa = getEG03()
    print aa

result = getEG03()
